package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.GoToRegister;
import com.cpj.bsyyzx.entity.NContent;
import com.cpj.bsyyzx.entity.NurseClass;
import com.cpj.bsyyzx.service.INContentService;
import com.cpj.bsyyzx.service.INurseClassService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/nContent")
@Log4j
public class NContentController {
    @Autowired
    INContentService nContentService;

    @RequestMapping("/list")
    CommonResult list(Page page, NContent nContent){
        log.debug("分页查询");
        QueryWrapper<NContent> queryWrapper = new QueryWrapper<>();
        Page<NContent> rpage=nContentService.pageList(page, nContent);
        return CommonResult.success(rpage);
    }



    @RequestMapping("save")
    @ResponseBody
    CommonResult save(NContent nContent) {

      log.debug("保存");
        System.out.println(nContent);
        boolean success = nContentService.saveOrUpdate(nContent);
        return CommonResult.success(success);
    }

    @RequestMapping("toedit")
    @ResponseBody
    public CommonResult toedit(ModelMap map, Integer nId) {
    log.debug("跳转到修改页面");
        NContent nContent = nContentService.getById(nId);
        map.addAttribute("nContent", nContent);
        return CommonResult.success(nContentService.getById(nId));
    }

    @RequestMapping("delete/{nId}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer nId) {
        log.debug("根据主键删除:" + nId);
        boolean success = nContentService.removeById(nId);
        return CommonResult.success(success);
    }

    /**
     * 输出启用的常项列表
     * @return
     */
    @RequestMapping("getProjectData")
    CommonResult getProjectData(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("status","启用");
        return CommonResult.success(nContentService.list(wrapper));
    }
}
